package com.atguigu.gmall.item.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;

//@Configuration
public class RedissonConfiguration {

    @Autowired
    private RedisProperties redisProperties ;

    @Bean
    public RedissonClient redissonClient() {

        // 创建一个Config对象
        Config config = new Config() ;
        config.useSingleServer().setAddress("redis://" + redisProperties.getHost() +  ":" + redisProperties.getPort())
                .setPassword(redisProperties.getPassword()) ;


        // 创建RedissonClient对象
        RedissonClient redissonClient = Redisson.create(config);

        // 返回
        return redissonClient ;

    }

}
